package com.bdy.lm.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet {


	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;chartset=utf-8");
		
		String userName = request.getParameter("userName");
		String keyWord = request.getParameter("keyWord");
		
		if("liming".equalsIgnoreCase(userName)){
			Cookie cookie = new Cookie("userName", userName);
			cookie.setMaxAge(60*5);
			response.addCookie(cookie);
			
			HttpSession session = request.getSession();
			session.setAttribute("userName", userName);
			
			response.sendRedirect("/LiMing/session/success.jsp");//重定向
		} else{
			request.setAttribute("msg", "用户名或密码错误!!!");
			RequestDispatcher qr = request.getRequestDispatcher("/session/login.jsp");//得到转发器
			qr.forward(request, response);
		}
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
	}

}
